/*
 * $Id: slm.h,v 1.3 2006-02-07 08:15:51 bacon Exp $
 */

#ifndef _XP_UTL_SLM_H_
#define _XP_UTL_SLM_H_

/*
 * (S)yslog (L)og (M)essage and its parser 
 */

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/time.h>
#include <xp/bas/sysapi.h>

#define XP_SLM_MAX_HOST 256
#define XP_SLM_MAX_TAG  256
#define XP_SLM_MAX_TEXT 4096

enum
{
	XP_SLM_FAC_KERN = 0,
	XP_SLM_FAC_USER,
	XP_SLM_FAC_MAIL,
	XP_SLM_FAC_DAEMON,
	XP_SLM_FAC_AUTH,
	XP_SLM_FAC_SYSLOG,
	XP_SLM_FAC_LPR,
	XP_SLM_FAC_NEWS,
	XP_SLM_FAC_UUCP,
	XP_SLM_FAC_CRON,
	XP_SLM_FAC_AUTHPRIV,
	XP_SLM_FAC_FTP,
	XP_SLM_FAC_NTP,
	XP_SLM_FAC_LOG_AUDIT,
	XP_SLM_FAC_LOG_ALERT,
	XP_SLM_FAC_LOG_CLOCK,
	XP_SLM_FAC_LOCAL0,
	XP_SLM_FAC_LOCAL1,
	XP_SLM_FAC_LOCAL2,
	XP_SLM_FAC_LOCAL3,
	XP_SLM_FAC_LOCAL4,
	XP_SLM_FAC_LOCAL5,
	XP_SLM_FAC_LOCAL6,
	XP_SLM_FAC_LOCAL7,
	XP_SLM_FAC_REMOTEAUTH,
	XP_SLM_FAC_NETINFO
};

enum
{
	XP_SLM_SEV_EMERG,
	XP_SLM_SEV_ALERT,
	XP_SLM_SEV_CRIT,
	XP_SLM_SEV_ERR,
	XP_SLM_SEV_WARNING,
	XP_SLM_SEV_NOTICE,
	XP_SLM_SEV_INFO,
	XP_SLM_SEV_DEBUG
};

enum
{
	XP_SLM_FLD_PRI  = 1,
	XP_SLM_FLD_TIME = 2,
	XP_SLM_FLD_HOST = 4,
	XP_SLM_FLD_TAG  = 8,
	XP_SLM_FLD_PID  = 16,
	XP_SLM_FLD_TEXT = 32
};

struct xp_slm_t
{
	int fldmask;
	struct 
	{
		short fac; /* facility */
		short sev; /* severity */
	} pri; /* priority */
	xp_time_t time;
	xp_char_t host[XP_SLM_MAX_HOST + 1];
	xp_char_t tag[XP_SLM_MAX_TAG + 1];
	xp_pid_t  pid;
	xp_char_t text[XP_SLM_MAX_TEXT + 1];
};

typedef struct xp_slm_t xp_slm_t;

#ifdef __cplusplus
extern "C" {
#endif

int xp_parse_slm (const xp_char_t* src, xp_slm_t* slm, int year);

#ifdef __cplusplus
}
#endif

#endif
